﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SqlCon;

namespace yfxt
{
    public partial class gl_ypsld_zuo : Form
    {
        public gl_ypsld_zuo()
        {
            InitializeComponent();
        }

        private void gl_ypsld_zuo_Load(object sender, EventArgs e)
        {
            string lingyaodanhao = ((gl_ypsl)this.Owner).lingyaodanhao;
            DataTable dt = new DataTable();
            DataTable dt2 = new DataTable();
            DataTable dt3 = new DataTable();

            //显示No.100001
            label6.Text = lingyaodanhao;

            //申请入库日期、备注
            string comStr = "select sqrq,ckbz,czgh from Yk_cK01 where ckdh='" + lingyaodanhao + "'";
            dt2.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null));
            textBox2.Text = Convert.ToDateTime(dt2.Rows[0][0]).ToString("yyyy-MM-dd").Replace('-', '.');
            textBox3.Text = dt2.Rows[0][1].ToString();

            //显示领药人
            comStr = "select ygxm from GY_YGDM where ygbh='" + dt2.Rows[0][2].ToString() + "'";
            string ygxm = (SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString();
            textBox4.Text = ygxm;

            //显示datagridView1的
            #region 
            comStr = "select ypxh,ypcd,lsjg,SQSL,SFSL from Yk_cK02 where ckdh='" + lingyaodanhao + "'";
            dt.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dataGridView1.Rows.Add(1);

                //显示药品名称、药品规格、药品单位
                if (mainform.yfsb == 3)                  //3表示中心药房
                {
                    comStr = "select ypmc,BFGG,BFDW from yk_typk where ypxh='" + dt.Rows[i][0].ToString() + "'";
                    dt3.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null));
                    dataGridView1.Rows[i].Cells[0].Value = dt3.Rows[i][0].ToString();
                    dataGridView1.Rows[i].Cells[1].Value = dt3.Rows[i][1].ToString();
                    dataGridView1.Rows[i].Cells[2].Value = dt3.Rows[i][2].ToString();
                }
                else
                {
                    comStr = "select ypmc,YFGG,YFDW from yk_typk where ypxh='" + dt.Rows[i][0].ToString() + "'";
                    dt3.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null));
                    dataGridView1.Rows[i].Cells[0].Value = dt3.Rows[i][0].ToString();
                    dataGridView1.Rows[i].Cells[1].Value = dt3.Rows[i][1].ToString();
                    dataGridView1.Rows[i].Cells[2].Value = dt3.Rows[i][2].ToString();
                }

                for (int j = 3; j < 7; j++)
                {
                    if (j != 3)
                    {
                        dataGridView1.Rows[i].Cells[j].Value = dt.Rows[i][j - 2].ToString();
                    }
                    else
                    {
                        //显示产地
                        comStr = "select cdqc from YK_CDDZ where ypcd='" + dt.Rows[i][1].ToString() + "'";
                        string cdqc = (SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString();
                        dataGridView1.Rows[i].Cells[3].Value = cdqc;
                    }
                }
            }
            #endregion

            //显示领用药房
            comStr = "select yfmc from Yf_YfLB where yfsb='" + mainform.yfsb + "'";
            string yfmc = (SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString();
            textBox1.Text = yfmc;

            //显示合计
            comStr = "select sum(lsjg*SQSL) from Yk_cK02 where ckdh='" + lingyaodanhao + "'";
            decimal total_lsje = decimal.Parse((SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString());
            textBox6.Text = total_lsje.ToString("F4");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
